home *** CD-ROM | disk | FTP | other *** search
/ World of Education / World of Education.iso / world_p / pcshx10b.zip / PCSHX10B.EXE / UTILS.EXE / UTILDOCS.EXE / SED.MAN < prev    next >
Text File  |  1987-11-23  |  14KB  |  351 lines

  1. NAME
  2.    sed - the stream editor
  3.  
  4.  
  5. SYNOPSIS
  6.    sed [-n[0]] [-g[0]] [-i[0]] [-e script ] [-f sfile ] [ file ] ...
  7.  
  8.  
  9. DESCRIPTION
  10.    Sed copies the named files (standard input default) to the standard
  11. output, edited according to a script of commands. 
  12.  
  13.    An -e option supplies one or more edit commands from the next argument;
  14. if there are several of these they are executed in the order in  which
  15. they appear. If there is just one -e option and no -f 's, the -e  flag
  16. may be omitted.
  17.  
  18. An -f option causes commands to be taken from the file "sfile";  if
  19. there are several  of these they are  executed in the order  in  which
  20. they appear; -e and -f commands may be mixed.
  21.  
  22.    The -g option causes sed to act as though every substitute  command
  23. in the script has a g suffix (-g or -g1) or otherwise (-g0, default).
  24.  
  25.    The -n option suppresses the default output (-n) or enable default
  26. output (-n0, default).
  27.  
  28.    The -i option caused sed to ignore case (-i or -i1) in pattern matching
  29. or to respect case (-i0, default).
  30.  
  31.  
  32.    A script consists of commands of the following form :
  33.  
  34.        [address [, address]] [!] function [arguments]
  35.  
  36.    Multiple commands in one line are separed by ';'.
  37.    
  38.    Normally sed cyclically copies a line of input into a current text
  39. buffer, then applies all commands whose addresses select the buffer in
  40. sequence, then copies the buffer to standard output and clears it.
  41.  
  42.    The -n option suppresses normal output (so that only p and w output
  43. is done). Also, some commands (n, N) do their own line reads, and some
  44. others (d, D) cause all commands following in the script to be skipped
  45. (the D command also suppresses the clearing of the current text buffer
  46. that would normally occur before the next cycle).
  47.  
  48.    It is also helpful to know that there's a second buffer (called the
  49. 'hold space' that can be copied or appended to or from or swapped with
  50. the current text buffer.
  51.  
  52.    An address is: a decimal numeral (which matches the line it numbers
  53. where line numbers start at 1 and run cumulatively across files), or a
  54. `$' that addresses the last line of input, or a context address, which
  55. is a `/regular expression/', in the style of ed (1) modified thus:
  56.  
  57. (1) The escape sequence `\n' matches a newline embedded in the buffer,
  58.     and `\t' matches a tab.
  59.  
  60. (2) A command line with no addresses selects every buffer.
  61.  
  62. (3) A command line with one address selects every buffer that matches
  63.     that address.
  64.  
  65. (4) A command line with two addresses selects the inclusive range from
  66.     the first input buffer  that matches the first address through the
  67.     next input buffer  that matches the second. (If the second address
  68.     is a number less than or equal to the line number first selected,
  69.     only one line is selected.)  Once the second address is matched sed
  70.     starts looking for the first one again; thus, any number of these 
  71.     ranges will be matched.
  72.  
  73.    The negation operator '!' can prefix a command to apply it to every
  74. line not selected by the address(es).
  75.  
  76.    In the following list of functions, the maximum number of addresses
  77. permitted for each function is indicated in parentheses.
  78.  
  79.    An argument denoted "text" consists of one or more lines,  with all
  80. but the last ending with `\' to hide the newline.
  81.  
  82.    Backslashes in text are treated like backslashes in the replacement
  83. string of an `s' command and may be used to protect initial whitespace
  84. (blanks and tabs) against the stripping that is done on every line  of
  85. the script.
  86.  
  87.    An argument denoted "rfile" or "wfile"  must be last on the command
  88. line.  Each wfile is created before processing begins.  There can be at
  89. most 10 distinct wfile arguments.
  90.  
  91. a "text"   (1)
  92.    Append. Place text on output before reading the next input line.
  93.  
  94. b "label"  (2)
  95.    Branch to the `:' command bearing the label.  If no label is  given,
  96.    branch to the end of the script.
  97.  
  98. c "text"   (2)
  99.    Change. Delete the current text buffer.  With 0 or 1 address,  or at
  100.    the end of a 2-address range, place text on the output.  Start the
  101.    next cycle.
  102.  
  103. d          (2)
  104.    Delete the current text buffer. Start the next cycle.
  105.  
  106. D          (2)
  107.    Delete the first line of the current text buffer (all chars up to the
  108.    first newline). Start the next cycle.
  109.  
  110. g          (2)
  111.    Get. Replace the contents of the current text buffer with the contents
  112.    of the hold space.
  113.  
  114. G          (2)
  115.    Append the contents of the hold space to the current text buffer.
  116.  
  117. h          (2)
  118.    Hold. Copy the current text buffer into the hold space.
  119.  
  120. H          (2)
  121.    Append a copy of the current text buffer to the hold space.
  122.  
  123. i "text"   (1)
  124.    Insert. Place text on the standard output.
  125.  
  126. l          (2)
  127.    List. Sends the pattern space to standard output.  A "w" option may
  128.    follow as in the s command below. Non-printable characters expand to:
  129.    \b  --  backspace (ASCII 08)
  130.    \t  --  tab       (ASCII 09)
  131.    \n  --  newline   (ASCII 10)
  132.    \r  --  return    (ASCII 13)
  133.    \e  --  escape    (ASCII 27)
  134.    \xx --  the ASCII character corresponding to 2 hex digits xx.
  135.  
  136. n          (2)
  137.    Next. Copy the current text buffer to standard output. Read the next
  138.    line of input into it.
  139.  
  140. N          (2)
  141.    Append the next line of input to the current text buffer, inserting
  142.    an embedded newline between the two. The current line number changes.
  143.  
  144. p          (2)
  145.    Print. Copy the current text buffer to the standard output.
  146.  
  147. P          (2)
  148.    Copy the first line of the current text buffer (all chars up to the
  149.    first newline) to standard output.
  150.  
  151. q          (1)
  152.    Quit. Branch to the end of the script. Do not start a new cycle.
  153.  
  154. r "rfile"  (1)
  155.    Read the contents of rfile. Place them on the output before reading
  156.    the next input line.
  157.  
  158. s /regular expression/replacement/flags         (2)
  159.    Substitute the replacement for instances of the regular  expression
  160.    in the current text buffer.  Any character may be used instead of `/'.
  161.    For a fuller description see ed (1) or ex (1).
  162.       Flags is zero or more of the following:
  163.  
  164.       g -- Global. Substitute for all nonoverlapping instances of the
  165.            string rather than just thefirst one.
  166.  
  167.       p -- Print the pattern space if a replacement was made.
  168.  
  169.       w -- Write. Append the current text buffer to a file argument as
  170.            in a w command if a replacement is made. Standard output is
  171.            used if no file argument is given
  172.  
  173. t "label"  (2)
  174.    Branch-if-test. Branch to the : command with the given label if any
  175.    substitutes have been made since the most recent read of an input line
  176.    or execution of a `t'or `T'.  If no label is given,  branch to the end
  177.    of the script.
  178.  
  179. T "label"  (2)
  180.    Branch-on-error. Branch to the : command with the given label if  no
  181.    substitutes have succeeded since the last input line or t or T command.
  182.    Branch to the end of the script if no label is given.
  183.  
  184. w "wfile"  (2)
  185.    Write. Append the current text buffer to wfile .
  186.  
  187. W "wfile"  (2)
  188.    Write first line.  Append first line  of the current text buffer
  189.    to wfile.
  190.  
  191. x          (2)
  192.    Exchange the contents of the current text buffer and hold space.
  193.  
  194. y /string1/string2/      (2)
  195.    Translate. Replace each occurrence of a character  in string1  with
  196.    the corresponding character in string2.  The lengths of  these strings
  197.    must be equal.
  198.  
  199. ! "command"              (2)
  200.    All-but.  Apply the function (or group, if function is `{') only to
  201.    lines not selected by the address(es).
  202.  
  203. : "label"  (0)
  204.    This command does nothing but hold a label for `b' and `t' commands
  205.    to branch to.
  206.  
  207. =          (1)
  208.    Place the current line number on the standard output as a line.
  209.  
  210. {          (2)
  211.    Execute the following commands through a matching `}' only when the
  212.    current line matches the address or address range given.
  213.  
  214. -n[0]       (0)
  215. -i[0]       (0)
  216. -g[0]       (0)
  217.    Turn on (0=off) no default output, ignore case in match pattern,
  218. and global substitution.
  219.  
  220.    An empty command is ignored.
  221.  
  222.  
  223. PORTABILITY
  224.  
  225.    This tool was reverse-engineered from BSD 4.1 UNIX sed, and (as far
  226. as the author's knowledge and tests can determine) is compatible  with
  227. it. All documented features of BSD 4.1 sed are supported.
  228.  
  229.    One undocumented feature (a leading 'n' in the first comment having
  230. the same effect as an  -n command-line option)  has been expanded.
  231.  
  232. The following bugs and limitations have been fixed:
  233.    * There is no hidden length limit (40 in BSD sed) on w file names.
  234.    * There is no limit (8 in BSD sed) on the length of labels.
  235.    * The exchange command now works for long pattern and hold spaces.
  236.  
  237. The following enhancements to existing commands have been made:
  238.    * a, i commands don't insist on a leading backslash-\n in the text.
  239.    * r, w commands don't insist on whitespace before the filename.
  240.    * The g, p and P options on s commands may be given in any order.
  241.  
  242. Some enhancements to regular-expression syntax have been made:
  243.    * \t is recognized in REs (and elswhere) as an escape for tab.
  244.    * In an RE, + calls for 1..n repeats of the previous pattern.
  245.    * In an RE, \a matches an alphanumeric character; \A matches the
  246.      rest of alphanumeric characters (at least one). Similar extensions
  247.      for \l,\L (letter), \d,\D (digit), \h,\H (hexdigit), and
  248.      \s,\S (space/tab)
  249.    * In an RE, \< and \> are used to force the match to occur only at
  250.      the begining or end of a word. (ala vi/ex).
  251.    * In the replacement pattern, \l and \u will force the next \0..\9 or &
  252.      to be converted to lower or upper case. \L and \U will turn such
  253.      conversion on, either until \e or \E is encountered, or until
  254.      the end of the replacement pattern. (ala vi/ex).
  255.    * In the replacement pattern, $0 means the original line, $i (i=1..9)
  256.      means word i.  If there are less than i word then $I will be a empty
  257.      string.  Note that words are separated by blank, TAB, or newline.
  258.  
  259. The following are completely new features:
  260.    * The l command (list, undocumented and weaker in BSD)
  261.    * The W command (write first line of pattern space to file).
  262.    * The T command (branch on last substitute failed).
  263.    * Trailing comments are now allowed on command lines.
  264.  
  265.    In addition,  sed's error messages have been made more specific and
  266. informative.
  267.  
  268.    The implementation is also  significantly  smaller and  faster than 
  269. BSD 4.1 sed. It uses only the standard I/O library and exit.
  270.  
  271.  
  272. Summary of Basic Regular Expressions
  273.  
  274.    <character>  An ordinary character matches itself. Special characters
  275.                 should be quoted with \, e.g. \^.
  276.                 
  277.    ^ and $      At the begining/end of a pattern forces the matche to
  278.                 succeed only at the begining/end of a line.
  279.                 
  280.    [class]    Matches a character in the class. A class is a list of
  281.                 characters or ranges. e.g. [A-Za-z0-9_$]
  282.                 
  283.    [^class]     Matches a character not in the class.
  284.    
  285.    .            Matches any single character except the terminal newline.
  286.    
  287.    *            Means repeat the previous regular expression any number
  288.                 of times (including zero).
  289.                 
  290.    +            Means repeat the previous regular expression one or
  291.                 more times.
  292.                 
  293.    \( and \)    Marks a regular expression for latter reference.
  294.    
  295.                 The null regular expression standing alone (e.g. //)
  296.                 is equivalent to the last recgular expression compiled.
  297.    
  298.    \d (d=1..9)  Means the string enclosed by the d-th \( and \) pairs.
  299.    
  300.    \< and \>    Force the match to occur only at the begining/end of a
  301.                 "variable" or "word".
  302.                 
  303.    \n           Matches an EMBEDDED newline character.
  304.    
  305.    \t           Matches a tab character.
  306.    
  307.    \a \A    \a matches an alphanumeric character. \A matches the
  308.    \l \L        the rest of alphanumeric characters (at least one).
  309.    \d \D    Similar expressions for letter, digit, hexdigit, and space.
  310.    \h \H    (see isalnum, isalpha, isdigit, ishexdigit, and isspace)
  311.    \s \S
  312.  
  313. Summary of Basic Substitution Expressions
  314.  
  315.    <character>  An ordinary character means that character.
  316.                 
  317.    &            Means the entire RE pattern.
  318.    
  319.    \d (d=1..9)  Means the RE pattern string enclosed by the d-th
  320.                 \( and \) pairs.
  321.    
  322.    \l \u        Convert the next \0..\9 or & into lower or upper case.
  323.    
  324.    \L \U        Convert subsequent \0..\9 or & into lower or upper case
  325.                 until the end of replacement string or until a \e, \E
  326.                 is encountered.
  327.                 
  328.    \e \E        Terminate case conversion.
  329.    
  330.    $0           The line before the current substitution command is executed.
  331.    
  332.    $d (d=1..9)  Means the d-th word.  Words are deliminated by blank, tab,
  333.                 and newline characters.
  334.                 
  335.    \n           Means a newline character.
  336.    
  337.    \t           Means a TAB character.
  338.    
  339.    
  340. NOTE
  341.    This is a freeware component of the GNU  operating system. The user
  342. is hereby granted permission to use, modify, reproduce and distribute
  343. it subject to the following conditions:
  344.    1. The authorship notice appearing  in  each source file may not be
  345. altered or deleted.
  346.    2. The object form may not be distributed without source.
  347.  
  348.  
  349. SEE ALSO
  350.    ed(1), ex(1), grep(1), awk(1), lex(1), regexp(5)
  351.